﻿using System;
namespace Producers.Etoimik.Xtee.Riik.Ee.Producer.Etoimik {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="FyysilineIsik", Namespace="http://producers.etoimik.xtee.riik.ee/producer/etoimik", Target=typeof(FyysilineIsik))]
    public class FyysilineIsikSerializer : global::Producers.Etoimik.Xtee.Riik.Ee.Producer.Etoimik.IsikSerializer {
        
        public FyysilineIsikSerializer(IFyysilineIsik clazz) : 
                base(clazz) {
        }
        
        protected new IFyysilineIsik clazz {
            get {
                return ((IFyysilineIsik)(base.clazz));
            }
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            if (clazz.DokumendiNimetus!=null) {
                Writer.WriteStartElement("DokumendiNimetus");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.DokumendiNimetus))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.DokumendiNR!=null) {
                Writer.WriteStartElement("DokumendiNR");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.DokumendiNR))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.DokumendiTyypKL!=null) {
                Writer.WriteStartElement("DokumendiTyypKL");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "long");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdLong(((long)(clazz.DokumendiTyypKL))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.Eesnimi!=null) {
                Writer.WriteStartElement("Eesnimi");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Eesnimi))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.HaridusKL!=null) {
                Writer.WriteStartElement("HaridusKL");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "long");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdLong(((long)(clazz.HaridusKL))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.HyydNimed!=null) {
                Writer.WriteStartElement("HyydNimed");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.HyydNimed))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.PerekonnaseisKL!=null) {
                Writer.WriteStartElement("PerekonnaseisKL");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "long");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdLong(((long)(clazz.PerekonnaseisKL))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.SuguKL!=null) {
                Writer.WriteStartElement("SuguKL");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "long");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdLong(((long)(clazz.SuguKL))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.SurmaKP!=null) {
                Writer.WriteStartElement("SurmaKP");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "dateTime");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdDateTime(((System.DateTime)(clazz.SurmaKP))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.Synnikoht!=null) {
                Writer.WriteStartElement("Synnikoht");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Synnikoht))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.TeisedNimed!=null) {
                Writer.WriteStartElement("TeisedNimed");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.TeisedNimed))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.EmaNimi!=null) {
                Writer.WriteStartElement("EmaNimi");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.EmaNimi))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.IsaNimi!=null) {
                Writer.WriteStartElement("IsaNimi");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.IsaNimi))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.EmakeelKL!=null) {
                Writer.WriteStartElement("EmakeelKL");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "long");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdLong(((long)(clazz.EmakeelKL))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.KodakondsusKL!=null) {
                Writer.WriteStartElement("KodakondsusKL");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "long");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdLong(((long)(clazz.KodakondsusKL))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.SuhtluskeelKL!=null) {
                Writer.WriteStartElement("SuhtluskeelKL");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "long");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdLong(((long)(clazz.SuhtluskeelKL))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.SynniKP!=null) {
                Writer.WriteStartElement("SynniKP");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "dateTime");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdDateTime(((System.DateTime)(clazz.SynniKP))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.TookohtvOppeasutus!=null) {
                Writer.WriteStartElement("TookohtvOppeasutus");
                Writer.WriteTypeAttribute("http://schemas.xmlsoap.org/soap/encoding/", "Array");
                Writer.WriteArrayTypeAttribute("Ametikoht", "http://producers.etoimik.xtee.riik.ee/producer/etoimik", clazz.TookohtvOppeasutus.Count);
                for (int x = 0; ((clazz.TookohtvOppeasutus != null) 
                            && (x < clazz.TookohtvOppeasutus.Count)); x = (x + 1)) {
                    if (clazz.TookohtvOppeasutus[x]!=null) {
                        Writer.WriteStartElement("item");
                        global::Xtee.Core.SerializationMetadata metaTookohtvOppeasutus = this.GetMetaData(clazz.TookohtvOppeasutus[x]);
                        Writer.WriteTypeAttribute(metaTookohtvOppeasutus.TypeQualifiedName.Namespace, metaTookohtvOppeasutus.TypeQualifiedName.Name);
                        metaTookohtvOppeasutus.NewSerializer(clazz.TookohtvOppeasutus[x]).WriteXml(Writer);
                        Writer.WriteEndElement();
                    }
                }
                Writer.WriteEndElement();
            }
            if (clazz.MitmikKodakondsusKL!=null) {
                Writer.WriteStartElement("MitmikKodakondsusKL");
                Writer.WriteTypeAttribute("http://schemas.xmlsoap.org/soap/encoding/", "Array");
                Writer.WriteArrayTypeAttribute("long", "http://www.w3.org/2001/XMLSchema", clazz.MitmikKodakondsusKL.Count);
                for (int x = 0; ((clazz.MitmikKodakondsusKL != null) 
                            && (x < clazz.MitmikKodakondsusKL.Count)); x = (x + 1)) {
                    if (clazz.MitmikKodakondsusKL[x]!=null) {
                        Writer.WriteStartElement("item");
                        Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "long");
                        Writer.WriteString(new global::Xtee.Core.Schema.XsdLong(((long)(clazz.MitmikKodakondsusKL[x]))).ToString());
                        Writer.WriteEndElement();
                    }
                }
                Writer.WriteEndElement();
            }
            if (clazz.KIRArvelolekKL!=null) {
                Writer.WriteStartElement("KIRArvelolekKL");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "long");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdLong(((long)(clazz.KIRArvelolekKL))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.KIRArvelolekAlgusKP!=null) {
                Writer.WriteStartElement("KIRArvelolekAlgusKP");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "dateTime");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdDateTime(((System.DateTime)(clazz.KIRArvelolekAlgusKP))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.KIRArvelolekLoppKP!=null) {
                Writer.WriteStartElement("KIRArvelolekLoppKP");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "dateTime");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdDateTime(((System.DateTime)(clazz.KIRArvelolekLoppKP))).ToString());
                Writer.WriteEndElement();
            }
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
            if (Reader.LocalName=="DokumendiNimetus") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.DokumendiNimetus = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("DokumendiNimetus")).Value;
                }
                else {
                    Reader.Skip();
                }
            }
            if (Reader.LocalName=="DokumendiNR") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.DokumendiNR = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("DokumendiNR")).Value;
                }
                else {
                    Reader.Skip();
                }
            }
            if (Reader.LocalName=="DokumendiTyypKL") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.DokumendiTyypKL = new global::Xtee.Core.Schema.XsdLong(Reader.ReadElementString("DokumendiTyypKL")).Value;
                }
                else {
                    Reader.Skip();
                }
            }
            if (Reader.LocalName=="Eesnimi") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.Eesnimi = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("Eesnimi")).Value;
                }
                else {
                    Reader.Skip();
                }
            }
            if (Reader.LocalName=="HaridusKL") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.HaridusKL = new global::Xtee.Core.Schema.XsdLong(Reader.ReadElementString("HaridusKL")).Value;
                }
                else {
                    Reader.Skip();
                }
            }
            if (Reader.LocalName=="HyydNimed") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.HyydNimed = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("HyydNimed")).Value;
                }
                else {
                    Reader.Skip();
                }
            }
            if (Reader.LocalName=="PerekonnaseisKL") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.PerekonnaseisKL = new global::Xtee.Core.Schema.XsdLong(Reader.ReadElementString("PerekonnaseisKL")).Value;
                }
                else {
                    Reader.Skip();
                }
            }
            if (Reader.LocalName=="SuguKL") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.SuguKL = new global::Xtee.Core.Schema.XsdLong(Reader.ReadElementString("SuguKL")).Value;
                }
                else {
                    Reader.Skip();
                }
            }
            if (Reader.LocalName=="SurmaKP") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.SurmaKP = new global::Xtee.Core.Schema.XsdDateTime(Reader.ReadElementString("SurmaKP")).Value;
                }
                else {
                    Reader.Skip();
                }
            }
            if (Reader.LocalName=="Synnikoht") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.Synnikoht = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("Synnikoht")).Value;
                }
                else {
                    Reader.Skip();
                }
            }
            if (Reader.LocalName=="TeisedNimed") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.TeisedNimed = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("TeisedNimed")).Value;
                }
                else {
                    Reader.Skip();
                }
            }
            if (Reader.LocalName=="EmaNimi") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.EmaNimi = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("EmaNimi")).Value;
                }
                else {
                    Reader.Skip();
                }
            }
            if (Reader.LocalName=="IsaNimi") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.IsaNimi = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("IsaNimi")).Value;
                }
                else {
                    Reader.Skip();
                }
            }
            if (Reader.LocalName=="EmakeelKL") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.EmakeelKL = new global::Xtee.Core.Schema.XsdLong(Reader.ReadElementString("EmakeelKL")).Value;
                }
                else {
                    Reader.Skip();
                }
            }
            if (Reader.LocalName=="KodakondsusKL") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.KodakondsusKL = new global::Xtee.Core.Schema.XsdLong(Reader.ReadElementString("KodakondsusKL")).Value;
                }
                else {
                    Reader.Skip();
                }
            }
            if (Reader.LocalName=="SuhtluskeelKL") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.SuhtluskeelKL = new global::Xtee.Core.Schema.XsdLong(Reader.ReadElementString("SuhtluskeelKL")).Value;
                }
                else {
                    Reader.Skip();
                }
            }
            if (Reader.LocalName=="SynniKP") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.SynniKP = new global::Xtee.Core.Schema.XsdDateTime(Reader.ReadElementString("SynniKP")).Value;
                }
                else {
                    Reader.Skip();
                }
            }
            if (Reader.LocalName=="TookohtvOppeasutus") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.TookohtvOppeasutus = new System.Collections.Generic.List<global::Producers.Etoimik.Xtee.Riik.Ee.Producer.Etoimik.IAmetikoht>();
                    if ((Reader.IsEmptyElement == false)) {
                        Reader.ReadStartElement("TookohtvOppeasutus");
                        for (; ((Reader.NodeType != System.Xml.XmlNodeType.EndElement) 
                                    && (Reader.LocalName == "item")); ) {
                            if ((Reader.IsElementNil() == false)) {
                                global::Xtee.Core.SerializationMetadata metaTookohtvOppeasutus = this.GetMetaData<global::Producers.Etoimik.Xtee.Riik.Ee.Producer.Etoimik.IAmetikoht>(Reader, "Ametikoht", "http://producers.etoimik.xtee.riik.ee/producer/etoimik");
                                global::Producers.Etoimik.Xtee.Riik.Ee.Producer.Etoimik.IAmetikoht item = metaTookohtvOppeasutus.NewEntity<global::Producers.Etoimik.Xtee.Riik.Ee.Producer.Etoimik.IAmetikoht>();
                                clazz.TookohtvOppeasutus.Add(item);
                                if ((Reader.IsEmptyElement == false)) {
                                    Reader.ReadStartElement("item");
                                    metaTookohtvOppeasutus.NewSerializer(item).ReadXml(Reader);
                                    Reader.ReadEndElement();
                                }
                                else {
                                    Reader.Skip();
                                }
                            }
                            else {
                                clazz.TookohtvOppeasutus.Add(null);
                                Reader.Skip();
                            }
                        }
                        Reader.ReadEndElement();
                    }
                    else {
                        Reader.Skip();
                    }
                }
                else {
                    Reader.Skip();
                }
            }
            if (Reader.LocalName=="MitmikKodakondsusKL") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.MitmikKodakondsusKL = new System.Collections.Generic.List<System.Int64?>();
                    if ((Reader.IsEmptyElement == false)) {
                        Reader.ReadStartElement("MitmikKodakondsusKL");
                        for (; ((Reader.NodeType != System.Xml.XmlNodeType.EndElement) 
                                    && (Reader.LocalName == "item")); ) {
                            if (Reader.IsElementNil()) {
                                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>FyysilineIsik>MitmikKodakondsusKL>item");
                            }
                            clazz.MitmikKodakondsusKL.Add(new global::Xtee.Core.Schema.XsdLong(Reader.ReadElementString("item")).Value);
                        }
                        Reader.ReadEndElement();
                    }
                    else {
                        Reader.Skip();
                    }
                }
                else {
                    Reader.Skip();
                }
            }
            if (Reader.LocalName=="KIRArvelolekKL") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.KIRArvelolekKL = new global::Xtee.Core.Schema.XsdLong(Reader.ReadElementString("KIRArvelolekKL")).Value;
                }
                else {
                    Reader.Skip();
                }
            }
            if (Reader.LocalName=="KIRArvelolekAlgusKP") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.KIRArvelolekAlgusKP = new global::Xtee.Core.Schema.XsdDateTime(Reader.ReadElementString("KIRArvelolekAlgusKP")).Value;
                }
                else {
                    Reader.Skip();
                }
            }
            if (Reader.LocalName=="KIRArvelolekLoppKP") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.KIRArvelolekLoppKP = new global::Xtee.Core.Schema.XsdDateTime(Reader.ReadElementString("KIRArvelolekLoppKP")).Value;
                }
                else {
                    Reader.Skip();
                }
            }
        }
    }
}
